package name.matthewgreet.example2.action; import java.util.List; import javax.servlet.http.HttpSession; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.InterceptorRef; import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.convention.annotation.Results; import com.opensymphony.xwork2.ActionSupport; import name.matthewgreet.example2.common.AbstractFormDrivenActionSupport; import name.matthewgreet.example2.common.ListCache; import name.matthewgreet.example2.common.ListFinder; import name.matthewgreet.example2.dto.GameDTO; import name.matthewgreet.example2.form.GameNameContainsForm; import name.matthewgreet.example2.model.GameTable; import name.matthewgreet.example2.model.Model; /** * Finds board games by overall ranking or ranking of a category. */ @InterceptorRef("FormDrivenStack") @Results({ @Result(name=ActionSupport.INPUT, type="redirectAction", params = {"namespace", "/", "actionName", "ViewGameList"}), @Result(name=ActionSupport.SUCCESS, type="redirectAction", params = {"namespace", "/", "actionName", "ViewGameList"}) }) public class FindGameListByNameContainsAction extends AbstractFormDrivenActionSupport<GameNameContainsForm> { public static class GameListFinderByNameContains implements ListFinder<GameDTO> { private static final long serialVersionUID = 6409312894523453002L; private String nameContains; public GameListFinderByNameContains(String nameContains) { this.nameContains = nameContains; } @Override public List<GameDTO> getList() throws Exception { GameTable gameTable; gameTable = Model.getInstance().getGameTable(); return gameTable.findByNameContains(nameContains); } public String getNameContains() { return nameContains; } } private static final long serialVersionUID = -7979376337555804889L; @Action("/FindGameListByNameContains") @Override public String execute() throws Exception { GameNameContainsForm form; ListCache<Integer,GameDTO> listCache; HttpSession session; form = getModel(); session = getRequest().getSession(); listCache = ViewGameListAction.retrieveListCache(session); listCache.setBaseRecordListFinder(new GameListFinderByNameContains(form.getNameContains())); return SUCCESS; } @Override protected GameNameContainsForm makeForm() { return new GameNameContainsForm(); } }